package org.com.gamemall.Utity;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

@Component
public class UserIntercepter implements HandlerInterceptor {
    @Autowired
    private RedisCacheTime redisCacheTime;
    private static final String Login_USER = "login:user:";
    private static final long Login_TTL = 30;

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        Object user = request.getSession().getAttribute("user");
        if (user != null) {
            redisCacheTime.Refreshtime(Login_USER + user, Login_TTL);
            return true;
        }
        return false;
    }


}
